package demo;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * 同步消息生产者
 */
public class SyncProducerMessage {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("group1");
        producer.setNamesrvAddr("192.168.86.104:10001");
        producer.start();
        try{
            for(int i=0;i<10;i++) {
                Message msg = new Message("demo_topic","tag1",("HelloWorld"+i).getBytes(StandardCharsets.UTF_8));
                SendResult result = producer.send(msg);
                System.out.println(i+"|"+result);
            }
        }finally {
            producer.shutdown();
        }
        System.out.println("ok");
    }
}
